using System.Collections.Generic;
using UnityEngine;

public class PauseUITDM : MonoBehaviour
{
	private GameObject pauseobj;

	public UIEventListener continuebtn;

	public UIEventListener quitbtn;

	public UIEventListener settingbtn;

	public UILabel timelabel;

	private List<planefightinfo> enemyfightinfo;

	private List<planefightinfo> frifightinfo;

	public List<UIfightinfo> infoLabelsFri;

	public List<UIfightinfo> infoLabelsAI;

	public UILabel friScore;

	public UILabel aiScore;

	private void Start()
	{
		continuebtn.onClick = OnClickcontinueBtn;
		quitbtn.onClick = OnClickquitBtn;
		settingbtn.onClick = OnClicksetBtn;
	}

	public void init_ui_info()
	{
		timelabel.text = MyMath.TimeSet(TasksController.instance.CurTask.TimeCal);
		enemyfightinfo = AIPool.instance.GetFightInfo();
		frifightinfo = FriendPool.instance.GetFightInfo();
		frifightinfo.Add(plane_smothfollow.instance.GetPlayerFightinfo());
		sortinfo();
		int num = 0;
		int num2 = 0;
		for (int i = 0; i < 5; i++)
		{
			if (i < enemyfightinfo.Count)
			{
				num += enemyfightinfo[i].selfinfo.killnum_plane;
				infoLabelsAI[i].name.text = i + 1 + ". " + GlobalInf.ai_names[enemyfightinfo[i].planeindex];
				infoLabelsAI[i].kill.text = string.Empty + enemyfightinfo[i].selfinfo.killnum_plane;
				infoLabelsAI[i].death.text = string.Empty + enemyfightinfo[i].selfinfo.diednum;
			}
			else
			{
				infoLabelsAI[i].name.text = string.Empty;
				infoLabelsAI[i].kill.text = string.Empty;
				infoLabelsAI[i].death.text = string.Empty;
			}
			if (i < frifightinfo.Count)
			{
				num2 += frifightinfo[i].selfinfo.killnum_plane;
				if (frifightinfo[i].planeindex == -1)
				{
					infoLabelsFri[i].name.text = i + 1 + ". You";
					infoLabelsFri[i].bg.spriteName = "JS_wenZiKuangC_TZ";
				}
				else
				{
					infoLabelsFri[i].name.text = i + 1 + ". " + GlobalInf.fri_names[frifightinfo[i].planeindex];
					if (i % 2 == 0)
					{
						infoLabelsFri[i].bg.spriteName = "JS_wenZiKuangB_TZ";
					}
					else
					{
						infoLabelsFri[i].bg.spriteName = "JS_wenZiKuangA_TZ";
					}
				}
				infoLabelsFri[i].kill.text = string.Empty + frifightinfo[i].selfinfo.killnum_plane;
				infoLabelsFri[i].death.text = string.Empty + frifightinfo[i].selfinfo.diednum;
			}
			else
			{
				infoLabelsFri[i].name.text = string.Empty;
				infoLabelsFri[i].kill.text = string.Empty;
				infoLabelsFri[i].death.text = string.Empty;
				if (i % 2 == 0)
				{
					infoLabelsFri[i].bg.spriteName = "JS_wenZiKuangB_TZ";
				}
				else
				{
					infoLabelsFri[i].bg.spriteName = "JS_wenZiKuangA_TZ";
				}
			}
		}
		aiScore.text = "得分:" + num;
		friScore.text = "得分:" + num2;
	}

	public void sortinfo()
	{
		int num2;
		for (int num = enemyfightinfo.Count - 1; num > 0; num = num2)
		{
			num2 = 0;
			for (int i = 0; i < num; i++)
			{
				if (enemyfightinfo[i].selfinfo.killnum_plane < enemyfightinfo[i + 1].selfinfo.killnum_plane)
				{
					num2 = i;
					planefightinfo value = enemyfightinfo[i];
					enemyfightinfo[i] = enemyfightinfo[i + 1];
					enemyfightinfo[i + 1] = value;
				}
				else if (enemyfightinfo[i].selfinfo.killnum_plane == enemyfightinfo[i + 1].selfinfo.killnum_plane && enemyfightinfo[i].selfinfo.diednum > enemyfightinfo[i + 1].selfinfo.diednum)
				{
					num2 = i;
					planefightinfo value2 = enemyfightinfo[i];
					enemyfightinfo[i] = enemyfightinfo[i + 1];
					enemyfightinfo[i + 1] = value2;
				}
			}
		}
		int num3;
		for (int num = frifightinfo.Count - 1; num > 0; num = num3)
		{
			num3 = 0;
			for (int j = 0; j < num; j++)
			{
				if (frifightinfo[j].selfinfo.killnum_plane < frifightinfo[j + 1].selfinfo.killnum_plane)
				{
					num3 = j;
					planefightinfo value3 = frifightinfo[j];
					frifightinfo[j] = frifightinfo[j + 1];
					frifightinfo[j + 1] = value3;
				}
				else if (frifightinfo[j].selfinfo.killnum_plane == frifightinfo[j + 1].selfinfo.killnum_plane && frifightinfo[j].selfinfo.diednum > frifightinfo[j + 1].selfinfo.diednum)
				{
					num3 = j;
					planefightinfo value4 = frifightinfo[j];
					frifightinfo[j] = frifightinfo[j + 1];
					frifightinfo[j + 1] = value4;
				}
			}
		}
	}

	public void OnClickcontinueBtn(GameObject btn)
	{
		MonoInstance<AudioController>.instance.play(AudioType.UI_BTN, 0f);
		GameUIController.instance.disable_pause_tdm();
	}

	public void OnClickquitBtn(GameObject btn)
	{
		PlaneMoveController.instance.isdied = true;
		TasksController.instance.is_gameover = true;
		GlobalInf.gameover = true;
		MonoInstance<AudioController>.instance.stopgamemusic();
		Time.timeScale = 1f;
		disable();
		GameUIController.instance.enable_result_tdm();
	}

	public void OnClicksetBtn(GameObject btn)
	{
		MonoInstance<AudioController>.instance.play(AudioType.UI_BTN, 0f);
		disable();
		GameUIController.instance.enable_optionui();
	}

	public void enable()
	{
		if (pauseobj == null)
		{
			pauseobj = base.gameObject;
		}
		init_ui_info();
		NGUITools.SetActive(pauseobj, state: true);
	}

	public void disable()
	{
		NGUITools.SetActive(pauseobj, state: false);
	}
}
